#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Time    : 2021/3/16 22:52
# Author  : Keyman
# File    : disjoint1.py


def disjoint1(l1: list, l2: list, l3: list):
    """
    Return True if there is no element common to all three lists.
    比较三个列表有没有相同元素
    算法复杂度：n^3
    """
    for a in l1:
        for b in l2:
            for c in l3:
                if a == b == c:
                    return False
    return True


def disjoint2(l1: list, l2: list, l3: list) -> bool:
    """
    Return True if there is no element common to all three lists.
    减少一层循环，可以降低复杂度
    """
    for a in l1:
        for b in l2:
            if a == b:  # only check C if we found match from A and B
                for c in l3:
                    if a == c:  # (and thus a == b == c)
                        return False  # we found a common value
    return True  # if we reach this, sets are disjoint


def unique(l1: list):
    """
    Return True if there is no element common to all three lists.
    利用元素唯一性(循环两次，j 和 j 之后的进行比较)
    复杂度：n^2
    """
    for j in range(len(l1)):
        for k in range(j + 1, len(l1)):
            if l1[j] == l1[k]:
                return False  # found duplicate pair
        return True  # if we reach this, elements were unique


def unique2(l1: list):
    """
    Return True if there are no duplicate elements in sequence S.
    利用排序进行
    """
    temp = sorted(l1)  # create a sorted copy of l1
    for j in range(1, len(l1)):
        if l1[j] == l1[j - 1]:
            return False  # found duplicate pair
    return True  # if we reach this, elements were unique.


def permutation(iterator: iter):
    """全排列"""
    

if __name__ == "__main__":
    pass
